package com.ruoyi.project.travel.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.travel.domain.ScenicStat;
import com.ruoyi.project.travel.service.IScenicStatService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 景区统计 Controller
 *
 * @author HYD
 * @date 2020-06-14
 */
@RestController
@RequestMapping("/travel/stat" )
public class ScenicStatController extends BaseController {
    @Autowired
    private IScenicStatService scenicStatService;

    /**
     * 查询景区统计 列表
     */
    @PreAuthorize("@ss.hasPermi('travel:stat:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(ScenicStat scenicStat) {
        startPage();
        QueryWrapper<ScenicStat> queryWrapper = new QueryWrapper<ScenicStat>();
        List<ScenicStat> list = scenicStatService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 导出景区统计 列表
     */
    @PreAuthorize("@ss.hasPermi('travel:stat:export')" )
    @Log(title = "景区统计 " , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(ScenicStat scenicStat) {
        QueryWrapper<ScenicStat> queryWrapper = new QueryWrapper<ScenicStat>(scenicStat);
        List<ScenicStat> list = scenicStatService.list(queryWrapper);
        ExcelUtil<ScenicStat> util = new ExcelUtil<ScenicStat>(ScenicStat. class);
        return util.exportExcel(list, "stat" );
    }

    /**
     * 获取景区统计 详细信息
     */
    @PreAuthorize("@ss.hasPermi('travel:stat:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(scenicStatService.getById(id));
    }

    /**
     * 新增景区统计 
     */
    @PreAuthorize("@ss.hasPermi('travel:stat:add')" )
    @Log(title = "景区统计 " , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScenicStat scenicStat) {
        return toAjax(scenicStatService.save(scenicStat) ? 1 : 0);
    }

    /**
     * 修改景区统计 
     */
    @PreAuthorize("@ss.hasPermi('travel:stat:edit')" )
    @Log(title = "景区统计 " , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScenicStat scenicStat) {
        return toAjax(scenicStatService.updateById(scenicStat) ? 1 : 0);
    }

    /**
     * 删除景区统计 
     */
    @PreAuthorize("@ss.hasPermi('travel:stat:remove')" )
    @Log(title = "景区统计 " , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(scenicStatService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
